import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

/**
 * @author Rock
 * @create 2020-08-31 14:51
 */
public class ScannerTest {
    public static void main(String[] args) {
        String fileName = "src/main/resources/static/TestReaderFile.txt";
        try {
            Scanner sc = new Scanner(new FileReader(fileName));
            //按行读取字符串
            while (sc.hasNextLine()){
                String line = sc.nextLine();
                System.out.println(line);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {
            System.out.println("-------------------------------------------");
        }

        try {
            Scanner sc = new Scanner(new FileReader(fileName));
            //分隔符
            sc.useDelimiter("\\|");
            //按分隔符读取字符串
            while (sc.hasNext()){
                String str = sc.next();
                System.out.println(str);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {
            System.out.println("-------------------------------------------");
        }
    }
}
